package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.TextureCache;
import com.corona.game.util.audio.AudioLoader;
import com.sun.jna.platform.win32.WinError;
import java.util.ArrayList;
import java.util.Locale;

/* compiled from: Battle.java */
/* access modifiers changed from: package-private */
/* loaded from: pokewilds.jar:com/pkmngen/game/SpecialBattleMegaGengar.class */
public class SpecialBattleMegaGengar extends Action {
    Music music;
    Music temp;
    public Action.Layer layer = Action.Layer.gui_106;
    boolean firstStep = true;
    int timer = 0;

    public SpecialBattleMegaGengar(Game game) {
        super(new Object[0]);
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "gui";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.Action
    public void step(Game game) {
        if (this.firstStep) {
            this.music = AudioLoader.loadMusic("battle/mgengar_battle_intro1.wav");
            this.music.setLooping(false);
            this.music.setVolume(0.2f);
            game.currMusic.stop();
            game.currMusic.dispose();
            game.currMusic = this.music;
            game.currMusic.stop();
            game.currMusic.play();
            game.currMusic.setOnCompletionListener(new Music.OnCompletionListener() { // from class: com.corona.game.SpecialBattleMegaGengar.1
                @Override // com.badlogic.gdx.audio.Music.OnCompletionListener
                public void onCompletion(Music aMusic) {
                    SpecialBattleMegaGengar.this.temp.play();
                }
            });
            this.firstStep = false;
        }
        if (this.timer == 0) {
            game.actionStack.remove(game.displayTextAction);
            game.displayTextAction = null;
            SpecialMegaGengar1 gengar = new SpecialMegaGengar1(70);
            game.battle.oppPokemon = gengar;
            Action triggerAction = new PlayMusic(game.player.currPokemon.specie.name, new WaitFrames(game, 6, new DrawBattleMenuNormal(game, null)));
            game.insertAction(new BattleIntro(new BattleIntro1(new SplitAction(new DrawBattle1(game), new SplitAction(new DrawBreathingSprite(gengar), new IntroAnim(game, new SplitAction(new WaitFrames(game, 1, new DrawEnemyHealthGen2(game)), new WaitFrames(game, 39, new MovePlayerOffScreen(game, new DisplayText(game, "Go! " + game.player.currPokemon.nickname.toUpperCase(Locale.ROOT) + "!", (String) null, triggerAction, new SplitAction(new DrawFriendlyHealthGen2(game), new ThrowOutPokemon(game, triggerAction))))))))))));
        }
        this.timer++;
    }

    /* compiled from: Battle.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/SpecialBattleMegaGengar$BattleIntro1.class */
    class BattleIntro1 extends Action {
        Sprite frame;
        public Action.Layer layer = Action.Layer.gui_139;
        ArrayList<Sprite> frames = new ArrayList<>();

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public BattleIntro1(Action nextAction) {
            super(new Object[0]);
            SpecialBattleMegaGengar.this = this$0;
            this.nextAction = nextAction;
            Texture text1 = TextureCache.get(Gdx.files.internal("battle/battle_intro_anim1_sheet1.png"));
            for (int i = 0; i < 28; i++) {
                this.frames.add(new Sprite(text1, i * 160, 0, 160, 144));
            }
            for (int i2 = 0; i2 < 126; i2++) {
                this.frames.add(new Sprite(text1, (int) WinError.ERROR_REQUEST_REFUSED, 0, 160, 144));
            }
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            this.frame = this.frames.get(0);
            if (this.frame != null) {
                this.frame.draw(game.uiBatch);
            }
            this.frames.remove(0);
            if (this.frames.isEmpty()) {
                game.insertAction(this.nextAction);
                game.actionStack.remove(this);
                this.nextAction.step(game);
            }
        }
    }

    /* compiled from: Battle.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/SpecialBattleMegaGengar$DrawBattle1.class */
    class DrawBattle1 extends DrawBattle {
        public Action.Layer layer = Action.Layer.gui_130;
        Sprite bgSprite;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public DrawBattle1(Game game) {
            super(game);
            SpecialBattleMegaGengar.this = this$0;
        }

        @Override // com.corona.game.DrawBattle, com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.DrawBattle, com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.DrawBattle, com.corona.game.Action
        public void step(Game game) {
            game.player.battleSprite.draw(game.uiBatch);
        }
    }

    /* compiled from: Battle.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/SpecialBattleMegaGengar$DrawBreathingSprite.class */
    static class DrawBreathingSprite extends Action {
        static boolean shouldBreathe = false;
        SpecialMegaGengar1 gengar;
        public Action.Layer layer = Action.Layer.gui_131;
        int timer = 300;
        int offsetY = 0;
        int offsetY2 = 0;
        Sprite bgSprite = new Sprite(TextureCache.get(Gdx.files.internal("battle/battle_bg3.png")), 0, 0, 160, 144);

        public DrawBreathingSprite(SpecialMegaGengar1 gengar) {
            super(new Object[0]);
            this.gengar = gengar;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (shouldBreathe) {
                this.timer--;
                if (this.timer == 74) {
                    this.offsetY2 = -1;
                } else if (this.timer == 274) {
                    this.offsetY2 = 0;
                }
                if (this.timer == 149) {
                    this.offsetY = -1;
                } else if (this.timer == 0) {
                    this.timer = 300;
                    this.offsetY = 0;
                }
            }
            this.bgSprite.draw(game.uiBatch);
            this.gengar.breathingSprite.setPosition(this.gengar.sprite.getX(), this.gengar.sprite.getY() - ((float) this.offsetY));
            this.gengar.breathingSprite.draw(game.uiBatch);
            this.gengar.sprite.setPosition(this.gengar.sprite.getX(), this.gengar.sprite.getY() - ((float) this.offsetY2));
            this.gengar.sprite.draw(game.uiBatch);
            this.gengar.sprite.setPosition(this.gengar.sprite.getX(), this.gengar.sprite.getY() + ((float) this.offsetY2));
            if (game.battle.drawAction == null) {
                game.actionStack.remove(this);
            }
        }
    }

    /* compiled from: Battle.java */
    /* loaded from: pokewilds.jar:com/pkmngen/game/SpecialBattleMegaGengar$IntroAnim.class */
    static class IntroAnim extends Action {
        Vector2 move;
        public Action.Layer layer = Action.Layer.gui_140;
        int timer = 0;
        boolean firstStep = true;
        ArrayList<Vector2> moves_relative = new ArrayList<>();

        public IntroAnim(Game game, Action nextAction) {
            super(new Object[0]);
            this.nextAction = nextAction;
            for (int i = 0; i < 144; i++) {
                this.moves_relative.add(new Vector2(1.0f, 0.0f));
            }
            game.player.battleSprite.setPosition(166.0f, 62.0f);
            game.battle.oppPokemon.sprite.setPosition(-49.0f, 88.0f);
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        String getShader(float level) {
            return "#ifdef GL_ES\n    precision mediump float;\n#endif\n\nvarying vec4 v_color;\nvarying vec2 v_texCoords;\nuniform sampler2D u_texture;\n\nvoid main() {\n    vec4 color = texture2D (u_texture, v_texCoords) * v_color;\n    float level = " + level + ";\n    if (color.r >= .9 && color.g >= .9 && color.b >= .9) {\n           color = vec4(color.r, color.g, color.b, color.a);\n    }\n    else {\n        color = vec4(color.r-level, color.g-level, color.b-level, color.a);\n    }\n    gl_FragColor = color;\n}";
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.firstStep) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.8f)));
                this.firstStep = false;
            }
            if (!this.moves_relative.isEmpty()) {
                this.move = this.moves_relative.get(0);
                game.player.battleSprite.setX(game.player.battleSprite.getX() - this.move.x);
                game.battle.oppPokemon.sprite.setX(game.battle.oppPokemon.sprite.getX() + this.move.x);
                this.moves_relative.remove(0);
                return;
            }
            if (this.timer == 30) {
                game.insertAction(new PlayMusic(game.battle.oppPokemon.specie.name, (Action) null));
            } else if (this.timer == 20) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.7f)));
            } else if (this.timer == 44) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.6f)));
            } else if (this.timer == 68) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.4f)));
            } else if (this.timer == 92) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.2f)));
            } else if (this.timer == 116) {
                game.uiBatch.setShader(new ShaderProgram(EvolutionAnim.vertexShader, getShader(0.0f)));
            }
            if (this.timer == 20) {
                game.insertAction(new DisplayTextIntro(game, "MEGA GENGAR attacked!", null, null, false, null));
            }
            if (this.timer == 216) {
                game.insertAction(this.nextAction);
            }
            if (this.timer >= 246) {
                game.actionStack.remove(game.displayTextAction);
                game.displayTextAction = null;
                game.actionStack.remove(this);
                DrawBreathingSprite.shouldBreathe = true;
            }
            this.timer++;
        }
    }
}
